package com.superdry.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.drysurper.R;
import com.superdry.activity.AddressActivity.AddressInfo;
import com.superdry.json.Address;

public class AddressAdapter extends BaseAdapter {

	Context mContext;
	List<Address> addressInfoList;

	public AddressAdapter() {
	}

	public AddressAdapter(Context mContext, List<Address> addressInfoList) {

		this.mContext = mContext;
		this.addressInfoList = addressInfoList;
	}

	@Override
	public int getCount() {
		return addressInfoList.size();
	}

	@Override
	public Address getItem(int position) {
		return addressInfoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		final Address item = addressInfoList.get(position);
		// 如果没有设置过,初始化convertView

		if (convertView == null) {
			// 获得设置的view
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_address, parent, false);
			// 初始化holder
			holder = new ViewHolder();
			holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
			holder.tel_tv = (TextView) convertView.findViewById(R.id.tel_tv);
			holder.address_tv = (TextView) convertView.findViewById(R.id.address_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.address_tv.setText(item.getAddressName());
		holder.name_tv.setText(item.getPeopleName());
		holder.tel_tv.setText(item.getAddressPhoneNumber());
		return convertView;
	}

	public void updata(List<Address> addressInfoList) {

		this.addressInfoList = addressInfoList;
		notifyDataSetChanged();
	}

	public static class ViewHolder {

		public TextView name_tv;
		public TextView tel_tv;
		public TextView address_tv;
	}
}
